package com.yang.knowledgebase.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yang.knowledgebase.dto.Result;
import com.yang.knowledgebase.mapper.BookMapper;
import com.yang.knowledgebase.pojo.Book;
import com.yang.knowledgebase.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements IBookService {
    @Override
    public Result getAllBook() {
        return Result.ok(list());
    }

    @Override
    public Result getBooksByName(String bookName) {
        QueryWrapper<Book> wrapper = new QueryWrapper<>();
        wrapper.like("name",bookName);
        List<Book> list = list(wrapper);
        if(list.isEmpty()){
            return Result.fail("暂无该书籍信息");
        }
        return Result.ok(list);
    }
}
